//
//  DTCScanView.m
//  WaterPurifierProduct
//
//  Created by yc on 2017/12/1.
//  Copyright © 2017年 Cong Yao. All rights reserved.
//

#import "DTCScanView.h"
//#import "UIView+Extension.h"

@interface DTCScanView ()
@property (weak, nonatomic) IBOutlet UIImageView *centerImageView;
@property (weak, nonatomic) IBOutlet UIImageView *scanImageView;
@property (weak, nonatomic) IBOutlet UIView *centerContentView;
@property (weak, nonatomic) IBOutlet UILabel *scanAlertLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scanImageViewTop;

@end

@implementation DTCScanView


- (instancetype)init {
    if (self = [super init]) {
        self = [[[NSBundle mainBundle] loadNibNamed:@"DTCScanView" owner:self options:nil] lastObject];
        self.backgroundColor = [UIColor clearColor];
        self.centerContentView.layer.masksToBounds = YES;
        
//        CAShapeLayer * layer = [CAShapeLayer new];
//        layer.frame = self.centerImageView.frame;
//        layer.fillColor = [UIColor clearColor].CGColor;
//        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.centerImageView.frame cornerRadius:0];
//        [[UIColor clearColor] setFill];
//        [path fill];
//        [layer setPath:path.CGPath];
//        [self.layer addSublayer:layer];

    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)drawRect:(CGRect)rect {
    CGContextRef con = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(con, [UIColor clearColor].CGColor);

    CGContextFillRect(con, rect);

    CGContextClearRect(con, self.centerContentView.frame);
}


- (void)setScanImageName:(NSString *)scanImageName {
    _scanImageName = scanImageName;
    if (_scanImageName.length != 0) {
        self.scanImageView.image = [UIImage imageNamed:scanImageName];
    }
}

- (void)setCenterImageName:(NSString *)centerImageName {
    _centerImageName = centerImageName;
    if (_centerImageName.length != 0) {
        self.centerImageView.image = [UIImage imageNamed:centerImageName];
    }
}


- (void)setAlertMsg:(NSString *)alertMsg {
    _alertMsg = alertMsg;
    if (_alertMsg.length != 0) {
        self.scanAlertLabel.text = alertMsg;
    }
}

- (void)starAnimation {
    
    [UIView animateWithDuration:1.5
                          delay:0
                        options:UIViewAnimationOptionRepeat
                     animations:^{
                         self.scanImageViewTop.constant = self.centerImageView.frame.size.height;
                         [self.centerContentView layoutIfNeeded];
                         
                     } completion:^(BOOL finished) {
                         
                     }];
}


@end
